package com.IntelligentCommunity.deploy.controller;

import com.IntelligentCommunity.common.core.domain.R;
import com.IntelligentCommunity.common.core.utils.poi.ExcelUtil;
import com.IntelligentCommunity.common.core.web.controller.BaseController;
import com.IntelligentCommunity.common.core.web.domain.AjaxResult;
import com.IntelligentCommunity.common.core.web.page.TableDataInfo;
import com.IntelligentCommunity.common.log.annotation.Log;
import com.IntelligentCommunity.common.log.enums.BusinessType;
import com.IntelligentCommunity.common.security.annotation.RequiresPermissions;
import com.IntelligentCommunity.deploy.domain.DeployAlarm;
import com.IntelligentCommunity.deploy.service.IDeployAlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 抓拍记录Controller
 *
 * @author kwzjx
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/alarm")
public class DeployAlarmController extends BaseController
{
    @Autowired
    private IDeployAlarmService deployAlarmService;

    /**
     * 查询抓拍记录列表
     */
    @RequiresPermissions("deploy:alarm:list")
    @GetMapping("/list")
    public TableDataInfo list(DeployAlarm deployAlarm)
    {
        startPage();
        List<DeployAlarm> list = deployAlarmService.selectDeployAlarmList(deployAlarm);
        return getDataTable(list);
    }

    /**
     * 导出抓拍记录列表
     */
    @RequiresPermissions("deploy:alarm:export")
    @Log(title = "抓拍记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeployAlarm deployAlarm)
    {
        List<DeployAlarm> list = deployAlarmService.selectDeployAlarmList(deployAlarm);
        ExcelUtil<DeployAlarm> util = new ExcelUtil<DeployAlarm>(DeployAlarm.class);
        util.exportExcel(response, list, "抓拍记录数据");
    }

    /**
     * 获取抓拍记录详细信息
     */
    @RequiresPermissions("deploy:alarm:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deployAlarmService.selectDeployAlarmById(id));
    }

    /**
     * 新增抓拍记录
     */
    @RequiresPermissions("deploy:alarm:add")
    @Log(title = "抓拍记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeployAlarm deployAlarm)
    {
        return toAjax(deployAlarmService.insertDeployAlarm(deployAlarm));
    }

    /**
     * 修改抓拍记录
     */
    @RequiresPermissions("deploy:alarm:edit")
    @Log(title = "抓拍记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeployAlarm deployAlarm)
    {
        return toAjax(deployAlarmService.updateDeployAlarm(deployAlarm));
    }

    /**
     * 删除抓拍记录
     */
    @RequiresPermissions("deploy:alarm:remove")
    @Log(title = "抓拍记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deployAlarmService.deleteDeployAlarmByIds(ids));
    }

    /**
     * 告警信息发送至mq
     * @param deployAlarm
     * @return
     */
    @PostMapping("/alarm2mq")
    public R alarm2mq(@RequestBody DeployAlarm deployAlarm) {
        deployAlarmService.alarm2mq(deployAlarm);
        return R.ok();
    }

    /**
     * 告警信息入库
     * @param deployAlarm
     * @return
     */
    @PostMapping("/alarmAdd")
    public R alarmAdd(@RequestBody DeployAlarm deployAlarm) {
        deployAlarmService.alarmAdd(deployAlarm);
        return R.ok();
    }


}
